const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('as4KDotsTxHistory', {
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER,
      allowNull: false,
      primaryKey: true,
      comment: "编号"
    },
    create_time: {
      type: DataTypes.DATE,
      allowNull: true,
      defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
      comment: "创建时间"
    },
    update_time: {
      type: DataTypes.DATE,
      allowNull: true,
      defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
      comment: "更新时间"
    },
    user_id: {
      type: DataTypes.BIGINT,
      allowNull: true,
      defaultValue: 0,
      comment: "用户 id"
    },
    stock_code: {
      type: DataTypes.STRING(10),
      allowNull: true,
      defaultValue: "",
      comment: "代码"
    },
    stock_name: {
      type: DataTypes.STRING(10),
      allowNull: true,
      defaultValue: "",
      comment: "名字"
    },
    stock_price_cost: {
      type: DataTypes.DECIMAL(10,3),
      allowNull: true,
      defaultValue: 0.000,
      comment: "持仓成本"
    },
    stock_price_current: {
      type: DataTypes.DECIMAL(10,3),
      allowNull: true,
      defaultValue: 0.000,
      comment: "当前股价"
    },
    stock_count: {
      type: DataTypes.BIGINT,
      allowNull: true,
      defaultValue: 0,
      comment: "持仓股数"
    },
    stock_count_change_amount: {
      type: DataTypes.BIGINT,
      allowNull: true,
      defaultValue: 0,
      comment: "变动数量"
    },
    stock_count_after_buy: {
      type: DataTypes.BIGINT,
      allowNull: true,
      defaultValue: 0,
      comment: "增持持仓"
    },
    stock_count_after_sell: {
      type: DataTypes.BIGINT,
      allowNull: true,
      defaultValue: 0,
      comment: "减持持仓"
    },
    stock_buy_amount: {
      type: DataTypes.DECIMAL(10,3),
      allowNull: true,
      defaultValue: 0.000,
      comment: "增持金额"
    },
    stock_sell_amount: {
      type: DataTypes.DECIMAL(10,3),
      allowNull: true,
      defaultValue: 0.000,
      comment: "减持金额"
    },
    stock_price_cost_after_buy: {
      type: DataTypes.DECIMAL(10,3),
      allowNull: true,
      defaultValue: 0.000,
      comment: "增持成本"
    },
    stock_price_cost_after_sell: {
      type: DataTypes.DECIMAL(10,3),
      allowNull: true,
      defaultValue: 0.000,
      comment: "减持成本"
    },
    gain_and_loss: {
      type: DataTypes.DECIMAL(10,3),
      allowNull: true,
      defaultValue: 0.000,
      comment: "盈亏"
    },
    clearance: {
      type: DataTypes.STRING(4),
      allowNull: true,
      defaultValue: "持有",
      comment: "清仓"
    },
    note: {
      type: DataTypes.STRING(5000),
      allowNull: true,
      defaultValue: "",
      comment: "备注"
    }
  }, {
    sequelize,
    tableName: 'as4k_dots_tx_history',
    timestamps: false,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "id" },
        ]
      },
    ]
  });
};
